<template>
  <el-container class="layout-container">
    <el-header>
      <div class="header-content">
        <h2>Web3 Bot</h2>
        <div class="header-right">
          <el-dropdown trigger="click">
            <div class="avatar-container">
              <el-avatar
                :size="40"
                src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
              />
            </div>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>个人信息</el-dropdown-item>
                <el-dropdown-item>修改密码</el-dropdown-item>
                <el-dropdown-item divided @click="handleLogout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </div>
    </el-header>
    
    <el-container>
      <el-aside width="200px">
        <el-menu
          :default-active="activeMenu"
          class="el-menu-vertical"
          :collapse="false"
          router
        >
          <el-menu-item index="/home">
            <el-icon><House /></el-icon>
            <span>首页</span>
          </el-menu-item>
          <el-menu-item index="/home/app-store">
            <el-icon><Grid /></el-icon>
            <span>应用广场</span>
          </el-menu-item>
          <el-sub-menu index="tools">
            <template #title>
              <el-icon><Tools /></el-icon>
              <span>辅助工具</span>
            </template>
            <el-menu-item index="/home/system-info">
              <el-icon><Monitor /></el-icon>
              <span>系统信息</span>
            </el-menu-item>
            <el-menu-item index="/home/proxy-management">
              <el-icon><Connection /></el-icon>
              <span>代理管理</span>
            </el-menu-item>
            <el-menu-item index="/home/email-management">
              <el-icon><Message /></el-icon>
              <span>邮箱管理</span>
            </el-menu-item>
            <el-menu-item index="/home/discord-management">
              <el-icon><ChatDotRound /></el-icon>
              <span>Discord账号</span>
            </el-menu-item>
          </el-sub-menu>
          <el-menu-item index="/home/my-apps">
            <el-icon><List /></el-icon>
            <span>我的应用</span>
          </el-menu-item>
          <el-menu-item index="/home/balance">
            <el-icon><Wallet /></el-icon>
            <span>我的卡密</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { House, Grid, List, Wallet, Tools, Connection, Message, ChatDotRound, Monitor } from '@element-plus/icons-vue'
import { ElMessageBox } from 'element-plus'

const router = useRouter()
const route = useRoute()
const activeMenu = ref('/home')

onMounted(() => {
  activeMenu.value = route.path
})

const handleLogout = () => {
  ElMessageBox.confirm(
    '确定要退出登录吗？',
    '提示',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  ).then(() => {
    localStorage.removeItem('token')
    router.push('/login')
  })
}
</script>

<style scoped>
.layout-container {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  height: 100%;
}

.header-right {
  display: flex;
  align-items: center;
}

.avatar-container {
  cursor: pointer;
  padding: 5px;
  transition: all 0.3s;
}

.avatar-container:hover {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
}

:deep(.el-avatar) {
  --el-avatar-size: 40px;
  border: 2px solid rgba(255, 255, 255, 0.8);
}

.el-header {
  background-color: #409EFF;
  padding: 0 20px;
  height: 60px;
  line-height: 60px;
  position: relative;
  z-index: 2;
}

.el-container {
  flex: 1;
  width: 100%;
  height: calc(100% - 60px);
}

.el-aside {
  background-color: #fff;
  border-right: solid 1px #e6e6e6;
  height: 100%;
  position: relative;
  z-index: 1;
}

.el-menu {
  height: 100%;
  border-right: none;
}

.el-main {
  background-color: #f5f5f5;
  height: 100%;
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
</style>
